package com.huangcy.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.huangcy.gulimall.order.config.AlipayTemplate;
import com.huangcy.gulimall.order.vo.PayVo;
import com.huangcy.gulimall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: gulimall
 * @description:
 * @author: huangcy
 * @create: 2022-09-16 15:56
 **/
@Controller
public class PayWebController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @Autowired
    OrderService orderService;

    //    @GetMapping(value = "/payOrder", produces = "text/html")
    @GetMapping("/payOrder")
    @ResponseBody
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVo);

        return pay;

//       return" redirect:http://order.gulimall.com/payed/notify";
//        return "redirect:https://53f4v77726.zicp.fun/payed/notify";

    }
}
